package com.example.tse.rbhttpservice.service.shopping;


import android.content.Context;

import com.example.tse.rbhttpservice.service.HttpService;
import com.example.tse.rbhttpservice.service.RemoteServiceListenerT;
import com.example.tse.rbhttpservice.service.ResponseServiceListenerT;
import com.example.tse.rbhttpservice.service.RudderResponse;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingAddRequest;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingAddResponse;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingChangeRequest;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingChangeResponse;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingCheckConsigneeRequest;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingCheckConsigneeResponse;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingCheckGoodsSpecRequest;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingCheckGoodsSpecResponse;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingChooseRequest;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingChooseResponse;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingCommitRequest;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingCommitResponse;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingDevideRequest;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingDevideResponse;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingGetCartNumRequest;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingGetCartNumResponse;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingGetCouponList;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingGetCouponListRequest;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingGetCouponListResponse;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingGetForBuyRequest;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingGetForBuyResponse;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingGetPrePayIdRequest;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingGetPrePayIdResponse;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingGetPriceRequest;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingGetPriceResponse;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingGetRequest;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingGetResponse;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingGetSubOrderList;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingGetSubOrderListRequest;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingGetSubOrderListResponse;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingRemoveRequest;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingRemoveResponse;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingSetAddrNumRequest;
import com.example.tse.rbhttpservice.service.shopping.model.ShoppingSetAddrNumResponse;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.kymjs.kjframe.http.HttpParams;

import java.lang.reflect.Type;
import java.util.List;





/**
 *
 * @author wliu
 *    edi  tse
 */
public class ShoppingServiceImpl implements ShoppingService {
	private Context context;
	private static Gson gson = new Gson();


	public ShoppingServiceImpl(Context context) {
		this.context = context;
	}
	/**
	 * 添加购物车
	 * @param request
	 * @param listener
	 * @return ShoppingAddResponse
	 */

	    public void add(ShoppingAddRequest request, final RemoteServiceListenerT< ShoppingAddResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("productId",request.getProductId());
            params.put("isFastBuy",request.getIsFastBuy());
            params.put("quantity",request.getQuantity());
            params.put("targetId",request.getTargetId());
            params.put("rudderRoute",request.getRudderRoute());

        final String url = "shopping/add";


            new HttpService().post(context, url, params, ShoppingAddResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((ShoppingAddResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new ShoppingAddResponse() : (ShoppingAddResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new ShoppingAddResponse() : (ShoppingAddResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




	/**
	 * 更改购物车中某商品数量，已选中的商品在每次更改数量之后都需要重新计算关税小计和总计价格
	 * @param request
	 * @param listener
	 * @return ShoppingChangeResponse
	 */

	    public void change(ShoppingChangeRequest request, final RemoteServiceListenerT< ShoppingChangeResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("objIdent",request.getObjIdent());
            params.put("quantity",request.getQuantity());
            params.put("areaId",request.getAreaId());
            params.put("isFastBuy",request.getIsFastBuy());
            params.put("couponId",request.getCouponId());

        final String url = "shopping/change";


            new HttpService().post(context, url, params, ShoppingChangeResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((ShoppingChangeResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new ShoppingChangeResponse() : (ShoppingChangeResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new ShoppingChangeResponse() : (ShoppingChangeResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




	/**
	 * 校验收货人的身份证号码是否在黑名单中，不在黑名单中才可以继续下单，否则提示相关信息
	 * @param request
	 * @param listener
	 * @return ShoppingCheckConsigneeResponse
	 */

	    public void checkConsignee(ShoppingCheckConsigneeRequest request, final RemoteServiceListenerT< ShoppingCheckConsigneeResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("consigneeId",request.getConsigneeId());

        final String url = "shopping/checkConsignee";


            new HttpService().post(context, url, params, ShoppingCheckConsigneeResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((ShoppingCheckConsigneeResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new ShoppingCheckConsigneeResponse() : (ShoppingCheckConsigneeResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new ShoppingCheckConsigneeResponse() : (ShoppingCheckConsigneeResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




	/**
	 * 验证订单中商品规格中仓库名称为上海跨境网仓同时下单地址中没有身份证信息
	 * @param request
	 * @param listener
	 * @return ShoppingCheckGoodsSpecResponse
	 */

	    public void checkGoodsSpec(ShoppingCheckGoodsSpecRequest request, final RemoteServiceListenerT< ShoppingCheckGoodsSpecResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("consigneeId",request.getConsigneeId());
            params.put("wareName",request.getWareName());

        final String url = "shopping/checkGoodsSpec";


            new HttpService().get(context, url, params, ShoppingCheckGoodsSpecResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((ShoppingCheckGoodsSpecResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new ShoppingCheckGoodsSpecResponse() : (ShoppingCheckGoodsSpecResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new ShoppingCheckGoodsSpecResponse() : (ShoppingCheckGoodsSpecResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




	/**
	 * 购物车中选择某商品，需计算购物车价格，多次点击切换选中状态，全选操作需要前端计算当前需要改变的ID拼接成字符串，若传递了areaId则是某个仓库的全选操作，否则就是所有的全选操作，根据status状态确定当前传递的IDs是选中还是取消
	 * @param request
	 * @param listener
	 * @return ShoppingChooseResponse
	 */

	    public void choose(ShoppingChooseRequest request, final RemoteServiceListenerT< ShoppingChooseResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("objIdent",request.getObjIdent());
            params.put("status",request.getStatus());
            params.put("areaId",request.getAreaId());
            params.put("isFastBuy",request.getIsFastBuy());
            params.put("couponId",request.getCouponId());

        final String url = "shopping/choose";


            new HttpService().post(context, url, params, ShoppingChooseResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((ShoppingChooseResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new ShoppingChooseResponse() : (ShoppingChooseResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new ShoppingChooseResponse() : (ShoppingChooseResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




	/**
	 * 提交订单
	 * @param request
	 * @param listener
	 * @return ShoppingCommitResponse
	 */

	    public void commit(ShoppingCommitRequest request, final RemoteServiceListenerT< ShoppingCommitResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("addressId",request.getAddressId());
            params.put("deliveryId",request.getDeliveryId());
            params.put("paymentId",request.getPaymentId());
            params.put("couponId",request.getCouponId());
            params.put("orderMsg",request.getOrderMsg());
            params.put("couponType",request.getCouponType());
            params.put("isFastBuy",request.getIsFastBuy());
            params.put("orderId",request.getOrderId());
            params.put("type",request.getType());

        final String url = "shopping/commit";


            new HttpService().post(context, url, params, ShoppingCommitResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((ShoppingCommitResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new ShoppingCommitResponse() : (ShoppingCommitResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new ShoppingCommitResponse() : (ShoppingCommitResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




	/**
	 * 购物车点击结算，拆分订单
	 * @param request
	 * @param listener
	 * @return ShoppingDevideResponse
	 */

	    public void devide(ShoppingDevideRequest request, final RemoteServiceListenerT< ShoppingDevideResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("isFastBuy",request.getIsFastBuy());
            params.put("couponId",request.getCouponId());

        final String url = "shopping/devide";


            new HttpService().post(context, url, params, ShoppingDevideResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((ShoppingDevideResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new ShoppingDevideResponse() : (ShoppingDevideResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new ShoppingDevideResponse() : (ShoppingDevideResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




	/**
	 * 购物车优惠券列表
	 * @param request
	 * @param listener
	 * @return ShoppingGetCouponListResponse
	 */

	    public void getCouponList(ShoppingGetCouponListRequest request, final RemoteServiceListenerT< ShoppingGetCouponListResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("isFastBuy",request.getIsFastBuy());

        final String url = "shopping/getCouponList";



        /**
        shopping
        getCouponList
        GetCouponList
        购物车优惠券列表
        GET
        Shopping
        ShoppingGetCouponList
        shopping/getCouponList
        array
        */

           final Type type = new TypeToken<List<ShoppingGetCouponList>>() {
        }.getType();



            new HttpService().getList(context, url, params, ShoppingGetCouponListResponse.class, new ResponseServiceListenerT<RudderResponse>() {

             @Override
             public void onPreStart() {
                 super.onPreStart();
                 listener.PreStart();
             }

             @Override
             public void ok(RudderResponse rudderResponse) {
                 super.ok(rudderResponse);
                 List<ShoppingGetCouponList> items = gson.fromJson(rudderResponse.getBody(), type);
                 ShoppingGetCouponListResponse responce = new ShoppingGetCouponListResponse();
                 responce.setGetCouponList(items);
                 listener.ok(responce);
             }

             @Override
             public void okData(RudderResponse rudderResponse) {
                 super.okData(rudderResponse);

                 if (rudderResponse == null) {
                     listener.okData(new ShoppingGetCouponListResponse());
                 } else {
                     List<ShoppingGetCouponList> items = gson.fromJson(rudderResponse.getBody(), type);
                     ShoppingGetCouponListResponse responce = new ShoppingGetCouponListResponse();
                     responce.setGetCouponList(items);
                     listener.okData(rudderResponse == null ? new ShoppingGetCouponListResponse() : responce);
                 }
             }

             @Override
             public void okData(RudderResponse rudderResponse, int fromWhere) {
                 super.okData(rudderResponse, fromWhere);


                 if (rudderResponse == null) {
                     listener.okData(new ShoppingGetCouponListResponse(), fromWhere);
                 } else {
                     List<ShoppingGetCouponList> items = gson.fromJson(rudderResponse.getBody(), type);
                     ShoppingGetCouponListResponse responce = new ShoppingGetCouponListResponse();
                     responce.setGetCouponList(items);
                     listener.okData(rudderResponse == null ? new ShoppingGetCouponListResponse() : responce, fromWhere);
                 }


             }

             @Override
             public void onFailure(int errorNo, String strMsg) {
                 super.onFailure(errorNo, strMsg);
                 listener.failue(errorNo, strMsg);
             }

             @Override
             public void onFinish() {
                 super.onFinish();
                 listener.Finish();
             }

             @Override
             public void onMessage(String message) {
                 super.onMessage(message);
                 listener.onMessage(message);
             }


         });
    }






	/**
	 * 获取购物车数据，用于下单页面（购买商品列表、收货地址、配送方式、支付方式、优惠券列表）
	 * @param request
	 * @param listener
	 * @return ShoppingGetForBuyResponse
	 */

	    public void getForBuy(ShoppingGetForBuyRequest request, final RemoteServiceListenerT< ShoppingGetForBuyResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("isFastBuy",request.getIsFastBuy());
            params.put("orderId",request.getOrderId());
            params.put("type",request.getType());

        final String url = "shopping/getForBuy";


            new HttpService().post(context, url, params, ShoppingGetForBuyResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((ShoppingGetForBuyResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new ShoppingGetForBuyResponse() : (ShoppingGetForBuyResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new ShoppingGetForBuyResponse() : (ShoppingGetForBuyResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




	/**
	 * 在结算界面，选择收货地址、配送方式、支付方式、优惠券都需要重新计算价格
	 * @param request
	 * @param listener
	 * @return ShoppingGetPriceResponse
	 */

	    public void getPrice(ShoppingGetPriceRequest request, final RemoteServiceListenerT< ShoppingGetPriceResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("addressId",request.getAddressId());
            params.put("deliveryId",request.getDeliveryId());
            params.put("paymentId",request.getPaymentId());
            params.put("couponId",request.getCouponId());
            params.put("isFastBuy",request.getIsFastBuy());
            params.put("orderId",request.getOrderId());

        final String url = "shopping/getPrice";


            new HttpService().post(context, url, params, ShoppingGetPriceResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((ShoppingGetPriceResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new ShoppingGetPriceResponse() : (ShoppingGetPriceResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new ShoppingGetPriceResponse() : (ShoppingGetPriceResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




	/**
	 * 获取当前用户的购物车中商品，按仓库组合商品，商品的关税为商品对应的分类的关税，团购的商品限购数量为0时，不能选择该商品，点击选择按钮提示已售罄，商品数量不能更改
	 * @param request
	 * @param listener
	 * @return ShoppingGetResponse
	 */

	    public void get(ShoppingGetRequest request, final RemoteServiceListenerT< ShoppingGetResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("isFastBuy",request.getIsFastBuy());

        final String url = "shopping/get";


            new HttpService().get(context, url, params, ShoppingGetResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((ShoppingGetResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new ShoppingGetResponse() : (ShoppingGetResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new ShoppingGetResponse() : (ShoppingGetResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




	/**
	 * 每次进入拆单页面，都获取拆单后的数据，对于“已生成订单”点击按钮跳转到订单详情
	 * @param request
	 * @param listener
	 * @return ShoppingGetSubOrderListResponse
	 */

	    public void getSubOrderList(ShoppingGetSubOrderListRequest request, final RemoteServiceListenerT< ShoppingGetSubOrderListResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("isFastBuy",request.getIsFastBuy());

        final String url = "shopping/getSubOrderList";



        /**
        shopping
        getSubOrderList
        GetSubOrderList
        每次进入拆单页面，都获取拆单后的数据，对于“已生成订单”点击按钮跳转到订单详情
        GET
        Shopping
        ShoppingGetSubOrderList
        shopping/getSubOrderList
        array
        */

           final Type type = new TypeToken<List<ShoppingGetSubOrderList>>() {
        }.getType();



            new HttpService().getList(context, url, params, ShoppingGetSubOrderListResponse.class, new ResponseServiceListenerT<RudderResponse>() {

             @Override
             public void onPreStart() {
                 super.onPreStart();
                 listener.PreStart();
             }

             @Override
             public void ok(RudderResponse rudderResponse) {
                 super.ok(rudderResponse);
                 List<ShoppingGetSubOrderList> items = gson.fromJson(rudderResponse.getBody(), type);
                 ShoppingGetSubOrderListResponse responce = new ShoppingGetSubOrderListResponse();
                 responce.setGetSubOrderList(items);
                 listener.ok(responce);
             }

             @Override
             public void okData(RudderResponse rudderResponse) {
                 super.okData(rudderResponse);

                 if (rudderResponse == null) {
                     listener.okData(new ShoppingGetSubOrderListResponse());
                 } else {
                     List<ShoppingGetSubOrderList> items = gson.fromJson(rudderResponse.getBody(), type);
                     ShoppingGetSubOrderListResponse responce = new ShoppingGetSubOrderListResponse();
                     responce.setGetSubOrderList(items);
                     listener.okData(rudderResponse == null ? new ShoppingGetSubOrderListResponse() : responce);
                 }
             }

             @Override
             public void okData(RudderResponse rudderResponse, int fromWhere) {
                 super.okData(rudderResponse, fromWhere);


                 if (rudderResponse == null) {
                     listener.okData(new ShoppingGetSubOrderListResponse(), fromWhere);
                 } else {
                     List<ShoppingGetSubOrderList> items = gson.fromJson(rudderResponse.getBody(), type);
                     ShoppingGetSubOrderListResponse responce = new ShoppingGetSubOrderListResponse();
                     responce.setGetSubOrderList(items);
                     listener.okData(rudderResponse == null ? new ShoppingGetSubOrderListResponse() : responce, fromWhere);
                 }


             }

             @Override
             public void onFailure(int errorNo, String strMsg) {
                 super.onFailure(errorNo, strMsg);
                 listener.failue(errorNo, strMsg);
             }

             @Override
             public void onFinish() {
                 super.onFinish();
                 listener.Finish();
             }

             @Override
             public void onMessage(String message) {
                 super.onMessage(message);
                 listener.onMessage(message);
             }


         });
    }






	/**
	 * 获取支付单号，每次点击支付前都需要去获取，每次支付都对应不同的支付单号
	 * @param request
	 * @param listener
	 * @return ShoppingGetPrePayIdResponse
	 */

	    public void getPrePayId(ShoppingGetPrePayIdRequest request, final RemoteServiceListenerT< ShoppingGetPrePayIdResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("orderId",request.getOrderId());

        final String url = "shopping/getPrePayId";


            new HttpService().get(context, url, params, ShoppingGetPrePayIdResponse.class, new ResponseServiceListenerT<RudderResponse>() {

                @Override
                public void onPreStart() {
                    super.onPreStart();
                    listener.PreStart();
                }

                public void ok(RudderResponse rudderResponse) {
                    super.ok(rudderResponse);
                    listener.ok((ShoppingGetPrePayIdResponse) rudderResponse);
                }

                @Override
                public void okData(RudderResponse rudderResponse) {
                    super.okData(rudderResponse);
                    listener.okData(rudderResponse == null ? new ShoppingGetPrePayIdResponse() : (ShoppingGetPrePayIdResponse) rudderResponse);
                }

                @Override
                public void okData(RudderResponse rudderResponse, int fromWhere) {
                    super.okData(rudderResponse, fromWhere);
                    listener.okData(rudderResponse == null ? new ShoppingGetPrePayIdResponse() : (ShoppingGetPrePayIdResponse) rudderResponse, fromWhere);
                }

                @Override
                public void onFailure(int errorNo, String strMsg) {
                    super.onFailure(errorNo, strMsg);
                    listener.failue(errorNo, strMsg);
                }

                @Override
                public void onFinish() {
                    super.onFinish();
                    listener.Finish();
                }

                @Override
                public void onMessage(String message) {
                    super.onMessage(message);
                    listener.onMessage(message);
                }
            });
    }




	/**
	 * 获取购物车数量
	 * @param request
	 * @param listener
	 * @return ShoppingGetCartNumResponse
	 */

	    public void getCartNum(ShoppingGetCartNumRequest request, final RemoteServiceListenerT< ShoppingGetCartNumResponse> listener) {

        final HttpParams params = new HttpParams();



        final String url = "shopping/getCartNum";


            new HttpService().get(context, url, params, ShoppingGetCartNumResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((ShoppingGetCartNumResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new ShoppingGetCartNumResponse() : (ShoppingGetCartNumResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new ShoppingGetCartNumResponse() : (ShoppingGetCartNumResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




	/**
	 * 删除购物车中的商品，每次删除之后都需要根据当前商品的选择状态重新计算关税小计和价格小计
	 * @param request
	 * @param listener
	 * @return ShoppingRemoveResponse
	 */

	    public void remove(ShoppingRemoveRequest request, final RemoteServiceListenerT< ShoppingRemoveResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("objIdent",request.getObjIdent());
            params.put("quantity",request.getQuantity());
            params.put("isFastBuy",request.getIsFastBuy());
            params.put("couponId",request.getCouponId());

        final String url = "shopping/remove";


            new HttpService().post(context, url, params, ShoppingRemoveResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((ShoppingRemoveResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new ShoppingRemoveResponse() : (ShoppingRemoveResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new ShoppingRemoveResponse() : (ShoppingRemoveResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




	/**
	 * 修改地址身份证信息
	 * @param request
	 * @param listener
	 * @return ShoppingSetAddrNumResponse
	 */

	    public void setAddrNum(ShoppingSetAddrNumRequest request, final RemoteServiceListenerT< ShoppingSetAddrNumResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("consigneeId",request.getConsigneeId());
            params.put("number",request.getNumber());
            params.put("name",request.getName());

        final String url = "shopping/setAddrNum";


            new HttpService().post(context, url, params, ShoppingSetAddrNumResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((ShoppingSetAddrNumResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new ShoppingSetAddrNumResponse() : (ShoppingSetAddrNumResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new ShoppingSetAddrNumResponse() : (ShoppingSetAddrNumResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




}